#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <unordered_set>
#include <string>
#include <algorithm>

using namespace std;

int n;
string s;

int main()
{
    cin >> n;
    unordered_set<string> hash;
    while (n--)
    {
        cin >> s;
        sort(s.begin(), s.end());
        hash.insert(s);
    }
    cout << hash.size();

    return 0;
}
#include <iostream>
using namespace std;

int t;
int h, a, H, A;

int func()
{
    if (a >= H) return -1;

    int m = (H / a) + (H % a != 0 ? 1 : 0);
    int n = m - 1;
    int x = n * A;
    int ret = h / x - (h % x == 0 ? 1 : 0);
    return ret;
}

int main()
{
    cin >> t;
    while (t--)
    {
        cin >> h >> a >> H >> A;
        cout << func() << endl;
    }
    return 0;
}